import { importUrl } from '@/api/cabinet/keyClasp'

import { checkStr, uniqueKey } from "@/utils/judge";
import url from "@/axios/url";
const { mesUrl } = url();
let vm = null;
const sendThis = (_this) => {
  vm = _this;
};
export { sendThis };
import { getDict } from "@/api/common";
import excelUpload from "@/components/excel-upload/excelUpload";
// 列表头按钮配置
export const operateList = {
  data () {
    const _this = this;
    return {
      operateList: [
        {
          name: $i18n.t("common.export"),
          type: "primary",
          icon: "el-icon-download",
          handleName: "export", //点击时返回的标识
          // url: exportUrl,
          //auth: "auth:operlog:export", //权限字段
        },
        {
          name: $i18n.t("common.add"),
          type: "primary",
          icon: "el-icon-circle-plus-outline",
          handleName: "add", // 点击时返回的标识
        },
        {
          name: $i18n.t("common.delete"),
          type: "danger",
          icon: "el-icon-delete",
          handleName: "deleteBatch", //点击时返回的标识
          isMultiple: true,
        },
        {
          // 导入文件
          render: (h, scope) => {
            // scope列表上选择的数据
            const uploadUrl = importUrl;
            return (
              <excelUpload
                action={uploadUrl}
                on={{
                  handleUploadError: (err) => {
                    // 失败的回调
                    console.log(err);
                  },
                  handleUploadSuccess: (res) => {
                    // vm.refresh();
                    _this.$refs.eleTable.handleReset();

                    //成功 的回调
                  },
                }}
              />
            );
          },
        },
        {
          name: $i18n.t("common.downloadTemplate"),
          type: "success",
          icon: "el-icon-download",
          handleName: "exportExcel", // 点击时返回的标识
        }
      ],
    };
  },
};
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", // 点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", // 点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", // 点击时返回的标识
  },
  {
    name: $i18n.t("keyClasp.btn1"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "transfer", // 点击时返回的标识
    disabled: (row) => { return !!row.uwbLongCode ? false : true }
  },
];

// 搜索条件配置
export const searchConfig = {
  data () {
    const _this = this;
    return {
      searchConfig: {
        inline: true,
        formDesc: {
          keyCode: {
            type: "input",
            label: $i18n.t("keyClasp.keyCode"),
          },
          status: {
            type: "select",
            label: $i18n.t("keyClasp.status"),
            prop: {
              value: "value",
              text: "description",
            },
            options: async () => {
              const list = await getDict('cabinet_cell_status');
              let _data = (list.data.result || []).filter((item) => item.value !== '0')
              return _data;
            },
          },
          uwbShortCode: {
            type: "input",
            label: $i18n.t("keyClasp.UWBCode"),
          },
        },
      },
    };
  },
};

// var validatePass = (rule, value, callback) => {
//   setTimeout(() => {
//     if (!checkStr(value, "english-number")) {
//       callback(new Error($i18n.t("mesProcess.rule8")));
//     } else {
//       callback();
//     }
//   }, 100);
// };
// 新增/删除表单配置
export const formDescDialogMinxin = {
  data () {
    const self = this;
    return {
      formDescDialog: {
        span: 24,
        disabled: false,
        isShowSubmitBtn: true,
        rules: {
          keyCode: [
            { max: 20, message: $i18n.t("common.overlongPrompt", { length: 20 }), trigger: ["change", "blur"] }
          ],
          remark: [
            { max: 150, message: $i18n.t("common.overlongPrompt", { length: 150 }), trigger: ["change", "blur"] }
          ],
        },
        formDesc: {
          keyCode: {
            type: "input",
            label: $i18n.t("keyClasp.keyCode"),
            layout: 12,
            required: true,
            disabled: (d) => !!d.id,
          },
          status: {
            type: "select",
            label: $i18n.t("keyClasp.status"),
            layout: 12,
            required: true,
            prop: {
              value: "value",
              text: "description",
            },
            options: async () => {
              const list = await getDict('cabinet_cell_status');
              let _data = (list.data.result || []).filter((item) => item.value !== '0')
              return _data;
            },
          },
          // processCode: {
          //   type: "input",
          //   label: $i18n.t("keyClasp.UWBCode"),
          //   layout: 12,
          //   required: true,
          // },
          // processName: {
          //   type: "input",
          //   label: $i18n.t("keyClasp.VINCode"),
          //   layout: 12,
          //   required: true,
          // },
          remark: {
            type: "textarea",
            label: $i18n.t("keyClasp.remark"),
            layout: 12,
            required: false,
          },
        },
      },
    };
  },
};

